package cn.tedu.zhyl.appointment.job;

import cn.tedu.zhyl.appointment.service.ReservationService;
import cn.tedu.zhyl.base.utils.ScheduledTaskContext;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Slf4j
@Component
public class UpdateReservationTask {
    @Autowired
    private ReservationService reservationService;


//    @XxlJob("updateReservationHandler")
    @Scheduled(cron = "0 01,31 * ? * *")
    public void updateReservationHandler(){
        try {
            ScheduledTaskContext.setScheduledTask(true);
            log.debug("开始执行更新预约状态计划,now:{}", LocalDateTime.now());
            reservationService.updateReservationStatus();
            log.debug("执行更新预约状态计划完成");
        } finally {
            ScheduledTaskContext.clear();

        }
    }

}
